import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import '../../model/demo_model.dart';
import '../../model/global.dart';
import '../../model/login_model.dart';

class TestPage extends StatefulWidget {
  const TestPage({Key? key, this.content}) : super(key: key);

  final String? content;

  @override
  State<TestPage> createState() => _TestPageState();
}

class _TestPageState extends State<TestPage>
    with AutomaticKeepAliveClientMixin {
  final LoginModel _loginModel = LoginModel();

  double count = 0;

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
      body: SafeArea(
        child: Container(
          child: Column(
            children: [
              Text("${widget.content}"),
              StreamBuilder(
                stream: demoModel.stream,
                builder: (BuildContext context, AsyncSnapshot<int> snapshot) {
                  return Text("${snapshot.data}");
                },
              ),
              InkWell(
                child: Container(
                    alignment: Alignment.center,
                    height: 40,
                    width: 100,
                    // padding: const EdgeInsets.all(10),
                    decoration: const BoxDecoration(
                        color: Colors.blueAccent,
                        borderRadius: BorderRadius.all(Radius.circular(10))),
                    child: const Text(
                      "点击",
                      style: TextStyle(color: Colors.white),
                    )),
                onTap: () {
                  demoModel.increment();
                },
              ),
              InkWell(
                child: Container(
                  alignment: Alignment.center,
                  height: 40,
                  width: 100,
                  // padding: const EdgeInsets.all(10),
                  decoration: const BoxDecoration(
                      color: Colors.blueAccent,
                      borderRadius: BorderRadius.all(Radius.circular(10))),
                  child:
                      const Text("登录测试", style: TextStyle(color: Colors.white)),
                ),
                onTap: () {
                  _loginModel.login();
                  EasyLoading.showToast("登录测试,请稍后...",
                      toastPosition: EasyLoadingToastPosition.bottom);
                  // count = count + 0.1;
                  // if (count >= 1.0) count = 1.0;
                  // EasyLoading.showProgress(count, status: '正在下载...');
                  // if (count >= 1.0) {
                  //   count = 0.1;
                  //   EasyLoading.dismiss();
                  // }
                },
              )
            ],
          ),
        ),
      ),
    );
  }
}
